using UnityEngine;
using System.Collections;

public class CustomGravity : MonoBehaviour
{
	public Transform			_currentPlanet;
	public float				_intensity = 3.0f;
	public bool					_enabled = true;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}
	
	void FixedUpdate()
	{
		if ( _enabled )
        {
            Vector3 _objToPlanet = _currentPlanet.position - gameObject.transform.position;
            Vector3 _gravity = (_objToPlanet.normalized / (_objToPlanet.magnitude * _objToPlanet.magnitude)) * _currentPlanet.rigidbody.mass * gameObject.rigidbody.mass;
			gameObject.rigidbody.AddForce( _gravity * _intensity );
            Debug.Log("anziehung planet: " + (_gravity * _intensity).magnitude);
		}
	}
}
